<?php

/**
 * This is the model class for table "system_rate".
 *
 * The followings are the available columns in table 'system_rate':
 * @property integer $id_rate
 * @property integer $id_golf
 * @property string $date
 * @property string $tee_time_start
 * @property string $tee_time_end
 * @property integer $tee
 * @property string $amount
 * @property integer $discount
 *
 * The followings are the available model relations:
 * @property GolfLand $idGolf
 */
class SystemRate extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return SystemRate the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'system_rate';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_rate, id_golf, tee, discount', 'numerical', 'integerOnly'=>true),
			array('amount', 'length', 'max'=>8),
			array('date, tee_time_start, tee_time_end', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_rate, id_golf, date, tee_time_start, tee_time_end, tee, amount, discount', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idGolf' => array(self::BELONGS_TO, 'GolfLand', 'id_golf'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_rate' => 'Id Rate',
			'id_golf' => 'Id Golf',
			'date' => 'Date',
			'tee_time_start' => 'Tee Time Start',
			'tee_time_end' => 'Tee Time End',
			'tee' => 'Tee',
			'amount' => 'Amount',
			'discount' => 'Discount',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_rate',$this->id_rate);
		$criteria->compare('id_golf',$this->id_golf);
		$criteria->compare('date',$this->date,true);
		$criteria->compare('tee_time_start',$this->tee_time_start,true);
		$criteria->compare('tee_time_end',$this->tee_time_end,true);
		$criteria->compare('tee',$this->tee);
		$criteria->compare('amount',$this->amount,true);
		$criteria->compare('discount',$this->discount);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}